import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'pages/Index.dart';
import 'pages/splash/Splash.dart';
import 'routes/Routes.dart';
import 'utils/Global.dart';
import 'package:provider/provider.dart';
import './provider/CurrentIndexProvider.dart';
import './provider/UserProvider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

void main() {
  // 初始化路由
  FluroRouter router =  FluroRouter();
  Routes.configureRoutes(router);
  // 初始化后的路由放到全局组件中
  G.router = router;
  runApp(
    // 全局数据共享
    MultiProvider(
      providers: [
        ChangeNotifierProvider.value(value: CurrentIndexProvider()),
        ChangeNotifierProvider.value(value: UserProvider())
        // 若干个类似的provide
      ],
      child: MyApp()
    )
  );
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // ScreenUtilInit 屏幕适配
    return  ScreenUtilInit(
      designSize: Size(750, 1334),
      builder: (context, widget) => MaterialApp(
        title: 'Flutter Demo',
        // home:  Index(),
        navigatorKey: G.navigatorKey,
        // 指定动态路由
        onGenerateRoute: G.router?.generator,
        // 默认加载页面
        // initialRoute: '/',
        home:  Splash(),
        // initialRoute: '/splash',
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
